﻿////////////////////////////////////////////////////////////////////
// © Copyright 2007 NeoGeo New Media GmbH (http://www.neogeo.com) //
////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// timer cancel variable *************************************
// (for cancelling the timer event, false if cancelled)
///////////////////////////////////////////////////////////////
var doubleMouseClickCancel = false;
var zoomInCancel = false;
var zoomOutCancel = false;
var resetAllCancel = false;
var navigateCancel = false;
var fadeCancel = false

///////////////////////////////////////////////////////////////
// timer callback directive **********************************
// (checks wether the timer event is active and calls back)
///////////////////////////////////////////////////////////////
function FadeTimer(fn, callback, name)
{    
    fn;
    if(!fadeCancel && callback != null) callback;
}
function NavigateTimer(fn, callback)
{    
    fn();
    if(!navigateCancel && callback != null) callback();
}

function DoubleClickTimer(fn, callback)
{    
    fn();
    if(!doubleMouseClickCancel && callback != null) callback();
}

function ZoomInTimer(fn, callback)
{    
    fn();
    if(!zoomInCancel && callback != null) callback();
}

function ZoomOutTimer(fn, callback)
{    
    fn();
    if(!zoomOutCancel && callback != null) callback();
}

function ResetAllTimer(fn, callback)
{    
    fn();
    if(!resetAllCancel && callback != null) callback();
}

///////////////////////////////////////////////////////////////
// executive directive ***************************************
// (executes the partial action while the timer event is active)
///////////////////////////////////////////////////////////////
function FadeInTile(name)
{
    var tile = MainRootElement.findName(name);
    tile["Opacity"] += 0.01;
    if (tile["Opacity"] == 1) fadeCancel = true;
}

function NavigateUp()
{
    TranslateScene(0,-5);
}
function NavigateDown()
{
    TranslateScene(0,5);
}
function NavigateLeft()
{
    TranslateScene(-5,0);
}
function NavigateRight()
{
    TranslateScene(5,0);
}

///////////////////////////////////////////////////////////////
// stop directive *******************************************
// (mostly attached to a button or key, stops the timer event)
///////////////////////////////////////////////////////////////
function ZoomStop(sender, mouseEventArgs)
{
     doubleMouseClickCancel = true;
     zoomInCancel = true;
     zoomOutCancel = true;
     resetAllCancel = true;
     navigateCancel = true;
}

function NavigateStop(sender, mouseEventArgs)
{
    ZoomStop(); 
}

///////////////////////////////////////////////////////////////
// start directive *******************************************
// (mostly attached to a button or key, starts the timer event)
///////////////////////////////////////////////////////////////
function DoubleClickZoomStart()
{   
    ZoomStop(); 
    doubleMouseClickCancel = false;
    setTimeout("DoubleClickTimer(DoubleClickZoom,DoubleClickZoomStart)",10);
}

function ZoomInStart(sender, mouseEventArgs)
{
    ZoomStop();    
    zoomInCancel = false;
    setTimeout("ZoomInTimer(ZoomIn,ZoomInStart)", 10);
}

function ZoomOutStart(sender, mouseEventArgs)
{
    ZoomStop();    
    zoomOutCancel = false;
    setTimeout("ZoomOutTimer(ZoomOut,ZoomOutStart)", 10);
}

function ResetAllStart(sender, mouseEventArgs)
{   
    ZoomStop();  
    resetAllCancel = false;
    setTimeout("ResetAllTimer(ResetAll,ResetAllStart)",10);
}

function NavigateUpStart(sender, mouseEventArgs)
{
    ZoomStop();
    navigateCancel = false;
    setTimeout("NavigateTimer(NavigateUp,NavigateUpStart)", 10);
}

function NavigateDownStart(sender, mouseEventArgs)
{
    ZoomStop();
    navigateCancel = false;
    setTimeout("NavigateTimer(NavigateDown,NavigateDownStart)", 10);
}

function NavigateLeftStart(sender, mouseEventArgs)
{
    ZoomStop();
    navigateCancel = false;
    setTimeout("NavigateTimer(NavigateLeft,NavigateLeftStart)", 10);
}

function NavigateRightStart(sender, mouseEventArgs)
{
    ZoomStop();
    navigateCancel = false;
    setTimeout("NavigateTimer(NavigateRight,NavigateRightStart)", 10);
}

function FadeInTileStart(name)
{      
    fadeCancel = false;    
    setTimeout("FadeTimer(FadeInTile('"+name+"'),FadeInTileStart('"+name+"'),'" + name + "')",10);
}